package com.sweet.fourtimeoa.controller;

import com.sweet.fourtimeoa.pojo.dto.AnnouncementDto;
import com.sweet.fourtimeoa.pojo.dto.PageDto;
import com.sweet.fourtimeoa.pojo.entity.Announcements;
import com.sweet.fourtimeoa.pojo.entity.Users;
import com.sweet.fourtimeoa.pojo.vo.PageVo;
import com.sweet.fourtimeoa.service.impl.NoticeServiceImpl;
import com.sweet.fourtimeoa.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Tag(name = "通告模块")
@RestController
@RequestMapping("/oa/announcements")
@CrossOrigin(origins = "*")
public class NoticeController {
    @Autowired
    private NoticeServiceImpl noticeService;

    @Operation(summary ="通告模块-分页查询")
    @GetMapping("/queryPage")
    public Result<PageVo<AnnouncementDto>> NoticeUser(PageDto pageDto) {
        PageVo<AnnouncementDto> pageVo = noticeService.NoticeUser(pageDto.getPageNum(), pageDto.getPageSize());
        return Result.success(pageVo);
    }

    @Operation(summary ="通告模块-新增")
    @PostMapping("/addition")
    public Map<String,String> NoticeAdd(@RequestBody Announcements announcements) {
        Map<String,String> map = new HashMap<>();
        boolean isok = noticeService.NoticeAdd(announcements);
        if (isok==true){
            map.put("result","true");
        }else {
            map.put("result","false");
        }
        return map;
    }
    @Operation(summary ="通告模块-修改")
    @PutMapping("/updetaition")
    public Map<String,String> NoticeUpdata(@RequestBody Announcements announcements) {
        Map<String,String> map = new HashMap<>();
        boolean isok = noticeService.NoticeUpdata(announcements);
        if (isok==true){
            map.put("result","true");
        }else {
            map.put("result","false");
        }
        return map;
    }
    @Operation(summary ="通告模块-根据id获取通告内容")
    @GetMapping("/finUpdate/{id}")
    public Result<Announcements> finUpdate(@PathVariable Integer id) {
        System.out.println(id);
        System.out.println(noticeService.finUpdate(id));
        return  Result.success(noticeService.finUpdate(id)) ;
    }


    @Operation(summary ="通告模块-删除")
    @DeleteMapping("/delition/{id}")
    public Map<String,String> NoticeDelete(@PathVariable Integer id) {
        Map<String,String> map = new HashMap<>();
        boolean isok = noticeService.NoticeDelete(id);
        if (isok==true){
            map.put("result","true");

        }else {
            map.put("result","false");
        }

        return map;
    }
}
